//
//  WelcomeViewCtr.swift
//  SwiftStory
//
//  Created by ZxjMacBookPro on 2020/5/6.
//  Copyright © 2020 ZxjMacBookPro. All rights reserved.
//

import UIKit
import SDWebImage

class WelcomeViewCtr: UIViewController {

    @IBOutlet weak var contentLB: UILabel!
    
    @IBOutlet weak var userImageView: UIImageView!
    
    @IBOutlet weak var userBottomCons: NSLayoutConstraint!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        userImageView.layer.cornerRadius = 45
//        userImageView.layer.masksToBounds = true
        userImageView.clipsToBounds = true
                
        assert(UserAcount.loadUserAccount() != nil, "必须授权之后才能显示欢迎界面")
        guard let url = URL(string: UserAcount.loadUserAccount()!.avatar_large!) else {
            return
        }
        userImageView.sd_setImage(with: url, completed: nil)
        
        // Do any additional setup after loading the view.
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        userBottomCons.constant = UIScreen.main.bounds.size.height - userBottomCons.constant
        
        UIView.animate(withDuration: 2.0, animations: {
            self.view.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 2.0, animations: {
                self.contentLB.alpha = 1.0
            }) { (_) in
                NotificationCenter.default.post(name: NSNotification.Name(rawValue: ZXJSwitchRootViewController), object: true)
            }
        }
    }
}
